<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd()" type="primary" icon="plus" style="margin-right: 30px">申请虚拟服务</a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatar)" icon="user"/>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
          <a id="console"  @click="applyConsole1()" v-show="record.status==2" >
            <img class="src" src="../../img/dakai.png" title="打开控制台"></a>
            <a-divider type="vertical"/>
                <a @click="applyStart1()" v-show="record.status==2">
                  <img class="src" src="../../img/qidongyun.png" title="启动云主机"></a>
           <a-divider type="vertical"/>
                <a @click="applyStop1()" v-show="record.status==2">
                  <img class="src" src="../../img/tingzhiyun.png" title="停止云主机"></a>
           <a-divider type="vertical"/>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a><img class="src" src="../../img/shanchu.png" title="删除"></a>
                </a-popconfirm>
        </span>
      </a-table>
    </div>

    <server-modal ref="modalForm" @ok="modalFormOk"></server-modal>
  </a-card>
</template>

<script>
  import ServerModal from './modules/ServerModal'
  import BackModal from './modules/BackModal'
  import {putAction} from '@/api/manage';
  import {frozenBatch} from '@/api/api'
  import {JantdListMixin} from '@/mixins/JantdListMixin'
  import {abc,start,stop} from '@/api/server'
  import moment from 'moment'
  moment.locale('zh-cn')
  export default {
    name: "MyServerList",
    mixins: [JantdListMixin],
    components: {
      ServerModal

    },
    props: {
      disabled: {
        default: false
      }
    },
    data() {
      return {
        description: '这是我的服务页面',
/*        queryParam: {},*/
        queryParam:{userName:'',virtualserve:''},
        userData:"",
        backData:"",
        applyConsole:"",
        applyStart:"",
        applyStop:"",
     columns: [
          {
            title: '所在单位',
            align: "center",
            width: 80,
            dataIndex: 'departName',
          },

          {
            title: '用户名称',
            align: "center",
            dataIndex: 'username',
            width: 120
          },
          {
            title: '用户镜像名称',
            align: "center",
            width: 100,
            dataIndex: 'virtualserve',
          },
       {
         title: '服务状态',
         align: "center",
         width: 140,
         dataIndex: 'status',
         customRender:function (text) {
           if(text==1){
             return "申请审核中";
           }else if(text==0){
             return "申请退回";
           }else if(text==2){
             return "审核通过";
           }else{
             return text;
           }
         }
       },
          {
         title: '退回原因',
         align: "center",
         width: 100,
         dataIndex: 'backdecription',
          },
       {
         title: '操作',
         dataIndex: 'action',
         scopedSlots: {customRender: 'action'},
         align: "center",
         width: 170
       }

        ],
        url: {
          imgerver: window._CONFIG['domianURL'] + "/sys/common/view",
          syncUser: "/process/extActProcess/doSyncUser",
          list:"/sys/myserver/mylist",
          applyConsole:"/sys/serVirtual/applyConsole",
          applyStart:"/sys/serVirtual/applyStart",
          applyStop:"/sys/serVirtual/applyStop",
          delete: "/sys/serVirtual/delete",
        },
      }
    },
    methods: {
      getAvatarView: function (avatar) {
        return this.url.imgerver + "/" + avatar;
      },
      applyConsole1(){
        //getAction(this.url.applyConsole,{});
        abc(this.url.applyConsole).then((res) =>{
     /*     async: false,*/
           console.log(res);
           if(res.console1='1'){
             console.log("kankanaknakn:++++++"+res.addrResult);
               window.open(res.addrResult,"_blank");
           }else{
             alert("云主机停止状态！");
                res;
        }
        });

      },

      applyStart1(){
        //getAction(this.url.applyConsole,{});
        start(this.url.applyStart).then((res) =>{
          if(res.success){
            console.log(res);
            alert("云主机已开启！");
          }else{
            res;
          }
        });

      },

      applyStop1(){
        //getAction(this.url.applyConsole,{});
        stop(this.url.applyStop).then((res) =>{
          if(res.success){
            console.log(res);
            alert("云主机已停止！");
          }else{
            res;
          }
        });
      },

      searchlist(){
        list(this.url.mylist).then((res) =>{
          if(res.success){
            console.log(res);
          }else{
            res;
          }

        });
      },

      handleMenuClick(e) {
        if (e.key == 1) {
          this.batchDel();
        } else if (e.key == 2) {
          this.batchFrozen(2);
        } else if (e.key == 3) {
          this.batchFrozen(1);
        }
      }
    }

  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>